package com.example.easyevent.fetcher;

import com.example.easyevent.type.Event;
import com.example.easyevent.type.EventInput;
import com.example.easyevent.type.User;
import com.example.easyevent.type.UserInput;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsData;
import com.netflix.graphql.dgs.DgsDataFetchingEnvironment;
import com.netflix.graphql.dgs.DgsMutation;
import com.netflix.graphql.dgs.DgsQuery;
import com.netflix.graphql.dgs.InputArgument;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

/**
 * @Author tianyi
 * @Description // todo
 * @Date 2023 - 11 - 13
 **/
@DgsComponent
public class EventDataFetcher {
    private List<Event> events = new ArrayList<>() ;

    @DgsQuery
    public List<Event> events() {

        return events;
    }
    @DgsData(parentType = "Event", field = "creator")
    public User creator(DgsDataFetchingEnvironment dfe){
        Event event = dfe.getSource();
        User user = new User();
        user.setId("8888");
        user.setPassword("xxxxx");
        user.setEmail("email");
        return user;
    }

    @DgsMutation
    public Event createEvent(@InputArgument(name="eventInput") EventInput input){
        Event event = new Event();
        event.setId(UUID.randomUUID().toString());
        event.setTitle(input.getTitle());
        event.setDescription(input.getDescription());
        event.setPrice(input.getPrice());
        event.setDate(input.getDate());
        event.setCreatorId("8888");
        events.add(event);
        return event;
    }
}
